package com.momoauth.api_client.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.momoauth.api_client.entity.MoMo_Dist_Item;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface DistItemMapper extends BaseMapper<MoMo_Dist_Item> {

    /**
     * 判断字典项是否使用了编号
     * @param type_id
     * @return
     */
    @Select("SELECT 1 FROM momo_dist_item WHERE type_id = #{type_id} LIMIT 1")
    Integer existDistItemById(Long type_id);

    /**
     * 根据字典编码查找字典项
     * @param type_code
     * @return
     */
    @Select("SELECT id,itemKey,itemValue FROM momo_dist_item WHERE type_code = #{type_code}")
    ArrayList<MoMo_Dist_Item> getAllDistItemByCode(String type_code);

    /**
     * 判断标签名是否重复使用
     * @param itemKey
     * @return
     */
    @Select("SELECT 1 FROM momo_dist_item WHERE itemKey = #{itemKey} LIMIT 1")
    Integer existDistItemKey(String itemKey);

    /**
     * 字典项列表
     * @param page
     * @param wrapper
     * @return
     */
    @Select("SELECT id,type_code,itemKey,itemValue,createTime FROM momo_dist_item ${ew.customSqlSegment}")
    List<MoMo_Dist_Item> getDistItemList(Page<MoMo_Dist_Item> page, @Param(Constants.WRAPPER) QueryWrapper wrapper);
}
